import http.client
import json 

from pymysql import NULL 


def getAllVideo(pageIndex):
    # print('开始查询录制视频API接口')
    conn = http.client.HTTPSConnection("video.gacicv.com")
    payload = ''
    headers = {}
    conn.request("GET", "/v1/api/gac/video/videolist?vehicleSeries=&serviceId=&dsn=&trigger=&VIN=&startTime=&endTime=&uploadType=pbparse&pageIndex="+pageIndex+"&pageSize=50", payload, headers)
    res = conn.getresponse()
    data = res.read()
    return data.decode("utf-8")

# 处理远程请求接口
if __name__ == '__main__':
    print('Application start')
    falg = False
    for pageIndex in range(679,904):
        res = json.loads(getAllVideo(str(pageIndex)))
        if res['code'] != 0 :
            print(res['msg'])
            break
        else:
            if res['data'] is not NULL:
                count = res['data']['count']
                # print('一共有'+str(count)+'条数据')
                list = res['data']['list']
                for data in list:
                    if not data['mpUrl'] is '' :
                        print(data['mpUrl'])
                        # falg =True
                        # break
                print('第'+str(pageIndex)+'页执行结束')
        if falg:
            break
    